package com.android.bookgarden.views;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.android.bookgarden.R;

/**
 * Create by zouqh
 * on 2018/12/4
 **/
public class KeyboardPasswordLayout extends LinearLayout implements View.OnClickListener {

    private KeyboardOnClickListener clickListener;
    public KeyboardPasswordLayout(Context context) {
        super(context);
    }

    public KeyboardPasswordLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.password_keyboard, this);
        findViewById(R.id.number0).setOnClickListener(this);
        findViewById(R.id.number1).setOnClickListener(this);
        findViewById(R.id.number2).setOnClickListener(this);
        findViewById(R.id.number3).setOnClickListener(this);
        findViewById(R.id.number4).setOnClickListener(this);
        findViewById(R.id.number5).setOnClickListener(this);
        findViewById(R.id.number6).setOnClickListener(this);
        findViewById(R.id.number7).setOnClickListener(this);
        findViewById(R.id.number8).setOnClickListener(this);
        findViewById(R.id.number9).setOnClickListener(this);
        findViewById(R.id.delete).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.number0:
                clickListener.inputPass("0");
                break;
            case R.id.number1:
                clickListener.inputPass("1");
                break;
            case R.id.number2:
                clickListener.inputPass("2");
                break;
            case R.id.number3:
                clickListener.inputPass("3");
                break;
            case R.id.number4:
                clickListener.inputPass("4");
                break;
            case R.id.number5:
                clickListener.inputPass("5");
                break;
            case R.id.number6:
                clickListener.inputPass("6");
                break;
            case R.id.number7:
                clickListener.inputPass("7");
                break;
            case R.id.number8:
                clickListener.inputPass("8");
                break;
            case R.id.number9:
                clickListener.inputPass("9");
                break;
            case R.id.delete:
                clickListener.deletePass();
                break;

        }
    }

    public void setClickListener(KeyboardOnClickListener keyboard){
        this.clickListener = keyboard;
    }

   public interface KeyboardOnClickListener{
        void inputPass(String number);
        void deletePass();
    }
}
